﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABELGX
{
    public class CmdWater:CarCmd
    {
        public RegisterBool Up { get; set; } = new RegisterBool();
        public RegisterBool Down { get; set; } = new RegisterBool();
        public RegisterBool Left { get; set; } = new RegisterBool();
        public RegisterBool Right { get; set; } = new RegisterBool();
        public RegisterBool Flow { get; set; } = new RegisterBool();
        public RegisterBool Fog { get; set; } = new RegisterBool();
        public RegisterBool Zero { get; set; } = new RegisterBool();
        public RegisterBool Auto { get; set; } = new RegisterBool();
        public RegisterBool Stop { get; set; } = new RegisterBool();
        public RegisterBool Reset { get; set; } = new RegisterBool();
        public int SpeedX { get; set; }
        public int SpeedY { get; set; }
        public CmdWater(CmdSet set, int length) : base(set, length)
        {

        }
        public override byte[] GetCmd()
        {
            int i;
            for (i = 4; i < Cmd.Length; i++)
            {
                Cmd[i] = 0x00;
            }
            i = 4;

            Cmd[i] = (byte)(Up.Value ? 0x01 : 0x00);
            Cmd[i] |= (byte)(Down.Value ? 0x02 : 0x00);
            Cmd[i] |= (byte)(Left.Value ? 0x04 : 0x00);
            Cmd[i] |= (byte)(Right.Value ? 0x08 : 0x00);
            Cmd[i] |= (byte)(Flow.Value ? 0x10 : 0x00);
            Cmd[i] |= (byte)(Fog.Value ? 0x20 : 0x00);
            i++;

            Cmd[i] = (byte)(Zero.Value ? 0x01 : 0x00);
            Cmd[i] |= (byte)(Auto.Value ? 0x02 : 0x00);
            i++;
            i++;

            Cmd[i] = (byte)(Stop.Value ? 0x01 : 0x00);
            Cmd[i] |= (byte)(Reset.Value ? 0x02 : 0x00);
            i++;

            Cmd[i++] = (byte)Math.Abs(SpeedX);
            Cmd[i++] = (byte)Math.Abs(SpeedY);
            CalXOR(Cmd);
            return Cmd;
        }
    }
}
